#!/bin/sh

SDK_BASE=../../../..
#SDK_BASE=../..
COMP_VER=V7.3.2

PACK_LIST=`cat project.cdkproj | grep "<Package ID" | awk -F"\"" '{printf "%s\n",$2}'`
BOARD_NAME=`cat project.cdkproj | grep "<Board ID" | awk -F"\"" '{printf "%s",$2}'`
CHIP_NAME=`cat project.cdkproj | grep "<Chip ID" | awk -F"\"" '{printf "%s",$2}'`
VENDOR_NAME=`cat package.yaml | grep "CONFIG_VENDOR_NAME" | awk -F'[ \r]' '{printf "%s", $4}' | xargs echo`
#Check
#echo ${VENDOR_NAME}
#echo ${CHIP_NAME}
#echo ${BOARD_NAME}
#echo ${PACK_LIST}
#echo ${SDK_BASE}/boards/${VENDOR_NAME}/${BOARD_NAME}

#Clean
rm -fr Boards Chips Packages

#Create Boards
echo "Boards" ${BOARD_NAME}
mkdir -p Boards/${BOARD_NAME}
ln -sf ${SDK_BASE}/boards/${VENDOR_NAME}/${BOARD_NAME}  Boards/${BOARD_NAME}/${COMP_VER}
#cp -rf 

#Create Chips
echo "Chips" ${CHIP_NAME}
mkdir -p Chips/${CHIP_NAME}
ln -sf ${SDK_BASE}/components/${CHIP_NAME}  Chips/${CHIP_NAME}/${COMP_VER}

#Packages
for CPNT in ${PACK_LIST}; do
    echo "Packages" ${CPNT}
    mkdir -p Packages/${CPNT}
    ln -sf ${SDK_BASE}/components/${CPNT}  Packages/${CPNT}/${COMP_VER}
done
